package ray.wx.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.URLDecoder;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ray.wx.util.MysqlUtil;

/**
 * Servlet implementation class KeyDeleteServlet
 */
@WebServlet("/KeyDeleteServlet")
public class KeyDeleteServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public KeyDeleteServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
        String strID = request.getParameter("id");
        
        MysqlUtil mysql = new MysqlUtil(MysqlUtil.dbUrl, MysqlUtil.dbUser, MysqlUtil.dbPass);
        try {
			mysql.connect();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		    return;
			//throw new ServletException("Database init failed!");
		}
        
        String sql = "delete from key_reply_msg where key_id in (" + strID + ");";
        mysql.update_db(sql);
        
		PrintWriter out = response.getWriter();
		out.print("");
		
	    out.close();  
	    out = null;		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
